home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / MemDoTrace.c,v < prev    next >
Encoding:
Text File  |  1991-12-03  |  4.3 KB  |  188 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.1.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     88.05.20.15.49.16;  author ouster;  state Exp;
  11. branches 1.1.1.1;
  12. next     ;
  13.  
  14. 1.1.1.1
  15. date     91.12.02.20.36.26;  author kupfer;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24.  
  25. 1.1
  26. log
  27. @Initial revision
  28. @
  29. text
  30. @/* 
  31.  * MemDoTrace.c --
  32.  *
  33.  *    Source code for the "MemDoTrace" procedure, which is used
  34.  *    internally by the memory allocator.  See memInt.h for overall
  35.  *    information about how the allocator works..
  36.  *
  37.  * Copyright 1988 Regents of the University of California
  38.  * Permission to use, copy, modify, and distribute this
  39.  * software and its documentation for any purpose and without
  40.  * fee is hereby granted, provided that the above copyright
  41.  * notice appear in all copies.  The University of California
  42.  * makes no representations about the suitability of this
  43.  * software for any purpose.  It is provided "as is" without
  44.  * express or implied warranty.
  45.  */
  46.  
  47. #ifndef lint
  48. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  49. #endif not lint
  50.  
  51. #define MEM_TRACE 1
  52.  
  53. #include "memInt.h"
  54.  
  55. /*
  56.  * The array below holds information about what to trace, and how.
  57.  */
  58.  
  59. MemTraceElement    memTraceArray[MAX_NUM_TRACE_SIZES];
  60. int        memNumSizesToTrace = 0;
  61.  
  62. /*
  63.  *----------------------------------------------------------------------
  64.  *
  65.  * PrintTrace --
  66.  *
  67.  *    Print out the given trace information about a memory trace record.
  68.  *
  69.  * Results:
  70.  *    None.
  71.  *
  72.  * Side effects:
  73.  *    None.
  74.  *
  75.  *----------------------------------------------------------------------
  76.  */
  77.  
  78. INTERNAL static void
  79. PrintTrace(allocated, infoPtr, curPC)
  80.     Boolean        allocated;    /* If TRUE, we are called by Mem_Alloc,
  81.                      * otherwise by Mem_Free. */
  82.     register Address    infoPtr;    /* Address of admin. info. */
  83.     Address        curPC;        /* If called by Mem_Free, PC of
  84.                      * call to Mem_Free, NULL otherwise. */
  85. {
  86.     if (allocated) {
  87.     (*memPrintProc)(memPrintData,
  88.         "malloc: PC=0x%x  addr=0x%x  size=%d\n",
  89.         GET_PC(infoPtr), infoPtr+sizeof(AdminInfo), 
  90.         GET_ORIG_SIZE(infoPtr));
  91.     } else {
  92.     (*memPrintProc)(memPrintData,
  93.         "free:  PC=0x%x  addr=0x%x  size=%d *\n",
  94.         curPC, infoPtr+sizeof(AdminInfo), GET_ORIG_SIZE(infoPtr));
  95.     }
  96. }
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * MemDoTrace --
  102.  *
  103.  *    Print and/or store a trace record.  Called by malloc and free.
  104.  *
  105.  * Results:
  106.  *    None.
  107.  *
  108.  * Side effects:
  109.  *    None.
  110.  *
  111.  *----------------------------------------------------------------------
  112.  */
  113.  
  114. void
  115. MemDoTrace(allocated, infoPtr, curPC, size)
  116.     Boolean        allocated;    /* If TRUE, we are called by malloc,
  117.                      * otherwise by free. */
  118.     register Address    infoPtr;    /* Address of admin. info. */
  119.     Address        curPC;        /* If called by free, PC of call to
  120.                      * free, NULL otherwise. */
  121.     int            size;        /* Size actually allocated. */
  122. {
  123.     int                i, j;
  124.     int                origSize;
  125.     Address            callerPC;
  126.     register MemTraceElement    *trPtr;
  127.  
  128.     if (memNumSizesToTrace == -1) {
  129.     PrintTrace(allocated, infoPtr, curPC);
  130.     return;
  131.     }
  132.  
  133.     callerPC = GET_PC(infoPtr);
  134.  
  135.     origSize = GET_ORIG_SIZE(infoPtr);
  136.  
  137.     for (i = 0, trPtr = memTraceArray; i < memNumSizesToTrace;
  138.         i++, trPtr++) {
  139.     if (trPtr->traceInfo.flags & MEM_DONT_USE_ORIG_SIZE) {
  140.         if (trPtr->traceInfo.size != size) {
  141.         continue;
  142.         }
  143.     } else if (trPtr->traceInfo.size != origSize) {
  144.         continue;
  145.     }
  146.     if (trPtr->traceInfo.flags & MEM_PRINT_TRACE) {
  147.         PrintTrace(allocated, infoPtr, curPC);
  148.     }
  149.     if (trPtr->traceInfo.flags & MEM_STORE_TRACE) {
  150.         if (trPtr->traceInfo.flags & MEM_TRACE_NOT_INIT) {
  151.         for (j = 0; j < MAX_CALLERS_TO_TRACE; j++) {
  152.             trPtr->allocInfo[j].numBlocks = 0;
  153.         }
  154.         trPtr->traceInfo.flags &= ~MEM_TRACE_NOT_INIT;
  155.         }
  156.         for (j = 0; j < MAX_CALLERS_TO_TRACE; j++) {
  157.         if (trPtr->allocInfo[j].numBlocks == 0) {
  158.             if (allocated) {
  159.             trPtr->allocInfo[j].callerPC = callerPC;
  160.             trPtr->allocInfo[j].numBlocks = 1;
  161.             }
  162.             break;
  163.         } else if (trPtr->allocInfo[j].callerPC == callerPC) {
  164.             if (allocated) {
  165.             trPtr->allocInfo[j].numBlocks++;
  166.             } else {
  167.             trPtr->allocInfo[j].numBlocks--;
  168.             }
  169.             break;
  170.         }
  171.         }
  172.     }
  173.     break;
  174.     }
  175. }
  176. @
  177.  
  178.  
  179. 1.1.1.1
  180. log
  181. @Initial branch for Sprite server.
  182. @
  183. text
  184. @d19 1
  185. a19 1
  186. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemDoTrace.c,v 1.1 88/05/20 15:49:16 ouster Exp $ SPRITE (Berkeley)";
  187. @
  188.